﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class SubmitMediaNews : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            SubmitMediaNewsOutParam result = new SubmitMediaNewsOutParam();
            SubmitMediaNewsInParam param = new SubmitMediaNewsInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            { 
                param = inParam as SubmitMediaNewsInParam;
                if (string.IsNullOrEmpty(param.Address) || string.IsNullOrEmpty(param.Content) || string.IsNullOrEmpty(param.phone) ||
                    string.IsNullOrEmpty(param.Title) || string.IsNullOrEmpty(param.userID))
                {
                    result.code = "0";
                    result.desc = "留言标题,留言内容,留言者ID,联系方式,联系地址不能为空";

                    isFlag = false;
                }

                if (CommonUtils.IsDisableUsers(param.userID))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }
                if (isFlag)
                {
                    //用户是否存在
                    isFlag = InterfaceHelper.CheckLoginIDCountEx(param.userID);

                    if (!isFlag)
                    {
                        result.code = "0";
                        result.desc = "该用户不存在";
                    }
                }


                if (isFlag)
                {
                    //保存数据
                    InterfaceHelper.SubmitMediaNews(param.userID, param.Title, param.phone, param.Content, param.Address);
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-SubmitMediaNews", SerializeHelper.JsonSerializer<SubmitMediaNewsInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<SubmitMediaNewsInParam, SubmitMediaNewsOutParam>();
            else
                SafeProcessRequest<SubmitMediaNewsInParam, SubmitMediaNewsOutParam>();
        }
    }

    #region 请求参数
    public class SubmitMediaNewsInParam
    { 
        /// <summary>
        ///	留言标题
        /// </summary>
        public string Title
        { get; set; }   

        /// <summary>
        ///	留言内容
        /// </summary>
        public string Content
        { get; set; }   

        /// <summary>
        ///	留言者ID
        /// </summary>
        public string userID
        { get; set; }   

        /// <summary>
        ///		联系方式	 
        /// </summary>
        public string phone
        { get; set; }

        /// <summary>
        ///		联系地址
        /// </summary>
        public string Address
        { get; set; }       
    }
    #endregion

    #region 结果参数
    public class SubmitMediaNewsOutParam
    {
        public SubmitMediaNewsOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    }  
    #endregion 
}